package FIle;

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;

public class FileTest_Reader {
    static HashMap<String, String> name;
    static HashMap<String, String> dest;

    public static void main(String[] args) {
        name = new HashMap<>();
        dest = new HashMap<>();
        // 字符流
        FileReader fr = null;
        try {

            // 实例化FIle类
            FileInputStream inputStream = new FileInputStream("C:\\Users\\wj\\Desktop\\happy.txt");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            // 提供具体的流
            String str = null;
            while ((str = bufferedReader.readLine()) != null) {
//                System.out.println(str);
                String[] split = str.split("\t");
//                System.out.println(Arrays.toString(split));
                String s1 = split[0].toString();
                String s2 = split[1].toString();
                if(str != null && split[0] != null && split[1] != null) {
                    name.put(s1,s2);
                }
            }
            System.out.println("name.toString() = " + name.toString());


            String source = "C:\\Users\\wj\\Desktop\\happy\\happy";
            File file = new File(source);
            for (File fileName : file.listFiles()) {
                if (fileName.isDirectory()) {
//                    for (File fileName01 : file.listFiles()) {
//                        if (fileName01.isFile()) {
//                            String[] split1 = fileName01.getName().split(".");
//                            String name1 = split1[0] + "-" + split1[1];
//                        }
//                    }
                    String[] split1 = fileName.getName().split("\\+");
                    String name1 = split1[0];
//                    System.out.println("name1 = " + name1);


                    String name3 = name1 + "+" + name.get(name1);
                    System.out.println("name3 = " + name3);
                    // 创建名称
                    File fileNew = new File(source + "\\" + name3);
                System.out.println("fileNew.getAbsolutePath() = " + fileNew.getAbsolutePath());
                    // 重命名
                    fileName.renameTo(fileNew); // 同一路径，不同问价名（重命名）
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fr != null)
                    fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
